package com.example.boot2mybatis.controller;

import com.example.boot2mybatis.entity.User;
import com.example.boot2mybatis.service.UserService;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.ibatis.session.defaults.DefaultSqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLOutput;

/**
 * 项目是整合 mybatis
 * 数据源data.source mysql
 * 配置:阿里德鲁伊 数据库连接池
 * sql 采用配置文件方式编写
 */
@RestController
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping("/login")
    @ResponseBody
    public String login(@RequestBody User user){
        DefaultSqlSession defaultSqlSession ;
        String name = user.getName();
        String password = user.getPassword();
        return  userService.login(name,password);
    }

    @RequestMapping("/loginAn")
    @ResponseBody
    public String loginAn(@RequestBody User user){
        String name = user.getName();
        String password = user.getPassword();
        return  userService.loginAn(name,password);
    }

    /**
     * https://localhost:8081/testHttps
     * 正常访问
     *
     * 当访问为http://localhost:8081/testHttps时
     * Bad Request
     * This combination of host and port requires TLS.
     * @return
     */
    @RequestMapping("/testHttps")
    @ResponseBody
    public String testHttps(){
        System.out.println("方法调用到了。。。");
        return  "success";
    }


    @RequestMapping("/bigInsert")
    @ResponseBody
    public  String bigInsert(){
        System.out.println("5000w数据插入完成！");
        return "ok";
    }


}
